home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17370 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: typedef Trouble (formerly (no subject))
  5. Date: Mon, 15 Apr 1996 12:11:40 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <3172753C.337C@datalytics.com>
  8. References: <4kgn17$5bb@mozart.wg.icl.co.uk>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Adel El-Beik wrote:
  16. > Can anyone explain why line 1 doesn't get passed MSVC++ 4.00
  17. > compiler.  Whereas line 2 does. MSVC++ complains it cannot perform
  18. > the conversion.
  19. > typedef long bar[2][2];
  20. > typedef const long (*const_bar)[2];
  21.  
  22. This typedef declares const_bar as an array of function 
  23. pointers, I think.  The confusion, for me, is the lack of a 
  24. parameter list and how that affects the interpretation of the 
  25. typedef.  I'm guessing that const_bar is a two-dimensional array 
  26. of function pointers taking no parameters and returning a const 
  27. long.  In other words, it may really be this:
  28.  
  29. typedef const long (*const_bar)(void)[2];
  30.  
  31. It could also be a two-dimensional array of function pointers 
  32. taking undefined parameters and returning a const long.
  33.  
  34. Neither interpretation is what you appear to want below anyway.
  35.  
  36. > void func( const bar param ){}
  37. > void main()
  38. > {
  39. >         bar x;
  40. >         func( x );     //  1
  41. >         func( (const_bar)x );   // 2
  42.  
  43. So why not just do this:
  44.  
  45. func((const bar)x);
  46.  
  47. which really shouldn't be necessary.  That is, this should work:
  48.  
  49. func(x);
  50.  
  51. If you really want a typedef that is equivalent to const bar, 
  52. doesn't this work?
  53.  
  54. typedef const bar const_bar;
  55.  
  56. The direct equivalent is, I think, this:
  57.  
  58. typedef long const const_bar[2][2];
  59.  
  60. > }
  61.  
  62. All of the above is conjecture.  I don't have time to test any 
  63. of this code.  Try at your own risk.
  64.  
  65. -- 
  66. Robert Stewart        | My opinions are usually my own.
  67. Datalytics, Inc.    | stew@datalytics.com
  68.